package com.warm.pump.module.monitor.inform;

import com.warm.pump.module.monitor.inform.impl.DingDingWrapper;
import com.warm.pump.module.monitor.inform.impl.EmailWrapper;
import com.warm.pump.module.monitor.inform.impl.SmsWrapper;
import com.warm.pump.module.monitor.inform.impl.WechatWrapper;

/**
 * Created by guozj on 2019/02/13.
 * 通知方式枚举
 * 用枚举代替工厂类
 */
public enum InformModeEnum {
    DINGDING("dingding",new DingDingWrapper()),
    EMAIL("email",new EmailWrapper()),
    WECHAT("wechat",new WechatWrapper()),
    SMS("sms",new SmsWrapper());
    private String title;
    private InformModeWrapper noticeMode;

    InformModeEnum(String title, InformModeWrapper noticeMode){
        this.title = title;
        this.noticeMode = noticeMode;
    }
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public InformModeWrapper getNoticeMode() {
        return noticeMode;
    }

    public void setNoticeMode(InformModeWrapper noticeMode) {
        this.noticeMode = noticeMode;
    }

    public static InformModeWrapper match(String name, InformModeEnum defaultWrapper){
        if(name != null){
            for (InformModeEnum item: InformModeEnum.values()) {
                if (item.getTitle().equals(name)){
                    return item.getNoticeMode();
                }
            }
        }
        return defaultWrapper.getNoticeMode();
    }
}
